package design.p3_singleton;

/**
 * @ClassName: Java
 * @description: 一般单例
 * @author: zxf
 * @create: 2021-06-17 17:27
 **/
public class Singleton {

    private static Singleton instance = null;

    private Singleton(){}

    public static Singleton getInstance(){
        if (instance != null){
            synchronized (instance){
                if (instance != null) return new Singleton();
            }
        }
        return instance;
    }
}
// Java指令中创建对象和赋值是分开进行的，上面可能会导致程序返回未被初始化的实例对象。

